package com.woniuxy.rabbitMq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class TestRabbitMq01 {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("event1")
    @ResponseBody
    public String event1(Integer command){
        if (command ==1){
            System.out.println("event1 开始发送消息：");
            String  msg="event1 发送消息："+new Date();
            rabbitTemplate.convertAndSend("","simpleQueue",msg);
        }else if (command==2){
            System.out.println("event1 开始发送消息：");
            String  msg="event1 发送消息："+new Date();
            rabbitTemplate.convertAndSend("","workQueue",msg);
        }else if (command==3){
            System.out.println("event1 开始发送消息：");
            String  msg="event1 发送消息："+new Date();
            rabbitTemplate.convertAndSend("fanoutExchange","suibian",msg);
        }else if (command==4){
            System.out.println("event1 开始发送消息：");
            String  msg="event1 发送消息："+new Date();
            rabbitTemplate.convertAndSend("directExchangeA","AAA",msg);
            rabbitTemplate.convertAndSend("directExchangeB","BBB",msg);
            rabbitTemplate.convertAndSend("directExchangeB","B1B1",msg);
            rabbitTemplate.convertAndSend("directExchangeB","B2B2",msg);
        }else if (command==5){
            System.out.println("event1 开始发送消息：");
            String  msg="event1 发送消息："+new Date();
            rabbitTemplate.convertAndSend("topicExchange",".CAT",msg);
            rabbitTemplate.convertAndSend("topicExchange","FISH.GOG.WWW.CAT",msg);
        }

        return "ok";
    }
}
